﻿$(function () {
    //移入
    $("#" + lstbID1).click(function () {
        var value = $(this).find("option:selected").val();
        var text = $(this).find("option:selected").text();
        //判断是否有重复项
        if (!changeShipMethod(lstbID2, value)) {
            $("#" + lstmsg).html("<span style='color:red;'>“" + text + "”已经存在,不要重复添加!</span>");
            return;
        }
        if (value != null && value != "undefined") {
            $("#" + lstbID2).append("<option value='" + value + "'>" + text + "</option>");
            $("#" + lstmsg).html("<span style='color:#119f02;'>“" + text + "”已选择.</span>");
        }
        $(this).find("option:selected").remove();
        $("#" + lstbID2).val($("#" + lstbID2).val() + "," + value);

    });

    //移出
    $("#" + lstbID2).click(function () {
        var value = $(this).find("option:selected").val();
        var text = $(this).find("option:selected").text();
        if (value != null && value != "undefined") {
            if (changeShipMethod(lstbID1, value)) {
                $("#" + lstbID1).append("<option value='" + value + "'>" + text + "</option>");
            }
            $("#" + lstmsg).html("<span style='color:#ff6600;'>“" + text + "”已移除.</span>");
        }
        $(this).find("option:selected").remove();

    });
    //判断是否重复
    function changeShipMethod(id, value) {
        var has = true;
        $("#" + id + " option").each(function () {
            if ($(this).val() == value) {
                has = false;
            }
        });
        return has;
    }
    //提交事件
    $("#" + btnSelector).click(function () {
        var _value = "";
        var _text = "";
        $("#" + lstbID2 + " option").each(function () {
            _value += $(this).val() + ","; ;
            _text += $(this).text() + ",";
        });

            $("#" + lstdata).val(_text + "|" + _value);
    });

});